import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:situation/app/router/router_name.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:situation/resources/assets.dart';
import 'package:situation/widgets/mk_scroll_view.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';
import 'state.dart';

class CommunicationIndexPage extends StatefulWidget {
  const CommunicationIndexPage({Key? key}) : super(key: key);

  @override
  State<CommunicationIndexPage> createState() => _CommunicationIndexPageState();
}

class _CommunicationIndexPageState extends State<CommunicationIndexPage> {
  final CommunicationIndexController controller = Get.put(
    CommunicationIndexController(),
  );
  final CommunicationIndexState state =
      Get.find<CommunicationIndexController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TDNavBar(
        titleWidget: Row(
          children: [Obx(()=>Text("${state.currentGroupName}", style: TextStyle(fontSize: 16)))],
        ),
        rightBarItems: [
          TDNavBarItem(
            iconWidget: SvgPicture.asset(Assets.svgConcat, width: 28),
            action: controller.toConcatList,
          ),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  width: 6,
                  height: 6,
                  decoration: BoxDecoration(
                    color: Colors.red,
                    borderRadius: BorderRadius.circular(6),
                  ),
                ),
                Gaps.hGap8,
                Obx(()=>Text("${state.whoTalk}", style: TextStyle(fontSize: 16))),
              ],
            ),
            Gaps.vGap32,
            GestureDetector(
              onLongPressDown: controller.onLongPressDown,
              onLongPressEnd: controller.onPressEnd,
              onTapUp: controller.onPressUp,
              child: Container(
                width: Get.width * 0.5,
                height: Get.width * 0.5,
                decoration: BoxDecoration(
                  color: Colors.blueAccent,
                  borderRadius: BorderRadius.circular(Get.width * 0.5),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black.withOpacity(0.2),
                      blurRadius: 10,
                      offset: Offset(0, 5),
                    ),
                  ],
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    SvgPicture.asset(
                      Assets.svgIntercom,
                      width: Get.width * 0.1,
                    ),
                    Gaps.vGap12,
                    Text(
                      "长按对讲",
                      style: TextStyle(
                        fontSize: 16,
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<CommunicationIndexController>();
    super.dispose();
  }
}
